home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
optivc32
/
mcdstd.h
< prev
next >
Wrap
C/C++ Source or Header
|
1999-03-06
|
31KB
|
591 lines
/* MCDstd.h
matrix management functions:
manipulations on matrices of data type "dComplex"
(double-precision complex numbers)
Copyright (c) 1996-1999 by Martin Sander
All Rights Reserved.
*/
#if !defined( __MATLIB_H )
#include <MatLib.h>
#endif
#if !defined( __VCDSTD_H )
#include <VCDstd.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
/************* Dynamic Generation of Matrices ************************/
cdMatrix __vf MCD_matrix( unsigned ht, unsigned len );
cdMatrix __vf MCD_matrix0( unsigned ht, unsigned len );
/* notice that, in the memory model HUGE,
neither len nor ht may exceed 2047 */
/***************************************************************************
* The following definitions ensure compatibility between dynamically *
* and statically allocated matrices. The definitions are somewhat *
* cumbersome, but the result for you is that you need not care about *
* the differences between the two types. *
* (Internally, the address of the first element of any matrix is needed; *
* the expression "MA[0]" is evaluated in a different way for both types, *
* but yields in either case the correct address to be passed to the *
* function you wish to call.) *
* Only in the rare case that you need to pass the address of one of *
* these functions as an argument to another function, you have to use *
* the actual run-time functions defined further below. Be careful with *
* this: future development of compilers may allow us to avoid this un- *
* handy scheme of macros. So future versions of MatrixLib may no longer *
* use these run-time names. *
***************************************************************************/
/*** Addressing single elements of dynamically allocated matrices: ******
These two functions are for compatibility with Pascal
(where elements of dynamically allocated matrices are not directly
accessible), and for getting around the pointer arithmetics bug in
some versions of Borland C++. */
#define MCD_Pelement( MA, ht, len, m, n ) MCDPelement( MA[0], ht, len, m, n )
/* returns a pointer to MA[m][n]. */
#define MCD_element( MA, ht, len, m, n ) *MCDPelement( MA[0], ht, len, m, n )
/* dereferenced pointer */
/**************** Initialization ***************************************
To initialize all elements of a matrix with the same value,
or to perform arithmetic operations on all elements simultaneously,
refer to the functions of VectorLib, declared in <VCDstd.h>, <VCDmath.h>.
In order to use the VectorLib functions, utilize the feature that
the whole matrix occupies one contiguous area in memory: pass the
address of the first row to the desired vector function, the size
of the "vector" being len * ht.
For example, initialize all elements of the matrix MA with {1.0, 0.0}
(this is *NOT* the identity matrix) by calling
VCD_equ1( MA[0], len * ht );
*/
#define MCD_equ1( MA, len ) MCDequ1( MA[0], len )
/* this is the identity matrix */
#define MCD_outerprod( MA, X, Y, ht, len ) MCDouterprod( MA[0], X, Y, ht, len )
/* sizX=ht, sizY=len */
#define MCD_Row_equC( MA, ht, len, iRow, C ) \
MCDRow_equC( MA[0], ht, len, iRow, C )
#define MCD_Col_equC( MA, ht, len, iCol, C ) \
MCDCol_equC( MA[0], ht, len, iCol, C )
#define MCD_Dia_equC( MA, len, C ) MCDDia_equC( MA[0], len, C )
#define MCD_Row_equV( MA, ht, len, iRow, X ) \
MCDRow_equV( MA[0], ht, len, iRow, X )
#define MCD_Col_equV( MA, ht, len, iCol, X ) \
MCDCol_equV( MA[0], ht, len, iCol, X )
#define MCD_Dia_equV( MA, len, X ) MCDDia_equV( MA[0], len, X )
#define MCD_equM( MB, MA, ht, len ) VCD_equV( MB[0], MA[0], ((ui)(len))*(ht) )
#define MCD_UequL( MA, len ) MCDUequL( MA[0], len )
#define MCD_LequU( MA, len ) MCDLequU( MA[0], len )
/* copy lower-diagonal elements into upper-diagonal
(or vice versa) by index-reflection, so as to
get a symmetric matrix */
/* data-type conversions: */
#define M_CDtoCF( MCF, MCD, ht, len ) V_CDtoCF( MCF[0], MCD[0], ((ui)ht)*len )
#define M_CFtoCD( MCD, MCF, ht, len ) V_CFtoCD( MCD[0], MCF[0], ((ui)ht)*len )
#define M_CEtoCD( MCD, MCE, ht, len ) V_CEtoCD( MCD[0], MCE[0], ((ui)ht)*len )
#define M_CDtoCE( MCE, MCD, ht, len ) V_CDtoCE( MCE[0], MCD[0], ((ui)ht)*len )
/******** Extracting a submatrix and copying a submatrix back *********/
#define MCD_submatrix( MSub, subHt, subLen, \
MSrce, srceHt, srceLen, \
firstRowInCol, sampInCol, firstColInRow, sampInRow ) \
MCDsubmatrix( MSub[0], subHt, subLen, \
MSrce[0], srceHt, srceLen, \
firstRowInCol, sampInCol, firstColInRow, sampInRow )
#define MCD_submatrix_equM( MDest, destHt, destLen, \
firstRowInCol, sampInCol, firstColInRow, sampInRow, \
MSrce, srceHt, srceLen ) \
MCDsubmatrix_equM( MDest[0], destHt, destLen, \
firstRowInCol, sampInCol, firstColInRow, sampInRow, \
MSrce[0], srceHt, srceLen )
/***** Extracting a single row or a single column or the diagonal ******
* and storing it into a vector */
#define MCD_Row_extract( Y, MA, ht, len, iRow ) \
MCDRow_extract( Y, MA[0], ht, len, iRow )
#define MCD_Col_extract( Y, MA, ht, len, iCol ) \
MCDCol_extract( Y, MA[0], ht, len, iCol )
#define MCD_Dia_extract( Y, MA, len ) MCDDia_extract( Y, MA[0], len )
/***************** Basic arithmetic operations *********************
performed on one single row,
or one single column of any matrix,
or on the diagonal of a square matrix
Note: In contrast to the analogous VectorLib functions, the operations
are performed in-place, i.e. the input matrix itself is changed */
#define MCD_Row_addC( MA, ht, len, iRow, C ) \
MCDRow_addC( MA[0], ht, len, iRow, C )
#define MCD_Col_addC( MA, ht, len, iCol, C ) \
MCDCol_addC( MA[0], ht, len, iCol, C )
#define MCD_Dia_addC( MA, len, C ) MCDDia_addC( MA[0], len, C )
#define MCD_Row_addV( MA, ht, len, iRow, X ) \
MCDRow_addV( MA[0], ht, len, iRow, X )
#define MCD_Col_addV( MA, ht, len, iCol, X ) \
MCDCol_addV( MA[0], ht, len, iCol, X )
#define MCD_Dia_addV( MA, len, X ) MCDDia_addV( MA[0], len, X )
#define MCD_Row_subC( MA, ht, len, iRow, C ) \
MCDRow_addC( MA[0], ht, len, iRow, (-C) )
#define MCD_Col_subC( MA, ht, len, iCol, C ) \
MCDCol_addC( MA[0], ht, len, iCol, (-C) )
#define MCD_Dia_subC( MA, len, C ) MCDDia_addC( MA[0], len, (-C) )
#define MCD_Row_subV( MA, ht, len, iRow, X ) \
MCDRow_subV( MA[0], ht, len, iRow, X )
#define MCD_Col_subV( MA, ht, len, iCol, X ) \
MCDCol_subV( MA[0], ht, len, iCol, X )
#define MCD_Dia_subV( MA, len, X ) MCDDia_subV( MA[0], len, X )
#define MCD_Row_subrC( MA, ht, len, iRow, C ) \
MCDRow_subrC( MA[0], ht, len, iRow, C )
#define MCD_Col_subrC( MA, ht, len, iCol, C ) \
MCDCol_subrC( MA[0], ht, len,